
package com.yuan.model;

import com.yuan.prefence.FileConstants;
import com.yuan.prefence.UrlConstants;
import com.yuan.unit.FileUtils;
import com.yuan.unit.HttpUtils;
import com.yuan.unit.JsonUtils;
import com.yuan.unit.TimeUtils;

import android.content.Context;

import java.io.IOException;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import java.util.List;
import java.util.Map;

/**
 * 员工活动轨迹表 entity. @author MyEclipse Persistence Tools
 */

@SuppressWarnings("serial")
public class M员工活动轨迹表 implements java.io.Serializable {

    // Fields

    private Integer id;
    private Integer 序号 = -1;
    private Double lat;
    private Double lng;
    private String 时间;

    // Constructors

    /** default constructor */
    private M员工活动轨迹表() {
    }

    private static M员工活动轨迹表 sInstance;

    public static M员工活动轨迹表 getInstance() {
        if (sInstance == null) {
            synchronized (M下班考勤表.class) {
                if (sInstance == null) {
                    sInstance = new M员工活动轨迹表();
                }
            }
        }
        return sInstance;
    }

    public void setFromMap(Map<?, ?> map) {
        try {
            this.id = Integer.parseInt((String) map.get("id"));
            this.序号 = Integer.parseInt((String) map.get("序号"));
            this.lat = Double.parseDouble((String) map.get("lat"));
            this.lng = Double.parseDouble((String) map.get("lng"));
            this.时间 = (String) map.get("时间");

        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    /** minimal constructor */
    public M员工活动轨迹表(Integer id, Integer 序号) {
        this.id = id;
        this.序号 = 序号;
    }

    /** full constructor */
    public M员工活动轨迹表(Integer id, Integer 序号, Double lat, Double lng, String 时间) {
        this.id = id;
        this.序号 = 序号;
        this.lat = lat;
        this.lng = lng;
        this.时间 = 时间;
    }

    // Property accessors

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer get序号() {
        return this.序号;
    }

    public void set序号(Integer 序号) {
        this.序号 = 序号;
    }

    public Double getLat() {
        return this.lat;
    }

    public void setLat(Double lat) {
        this.lat = lat;
    }

    public Double getLng() {
        return this.lng;
    }

    public void setLng(Double lng) {
        this.lng = lng;
    }

    public String get时间() {
        return this.时间;
    }

    public void set时间(String 时间) {
        this.时间 = 时间;
    }

    public void updateLocation(Context mContext) {
        // TODO Auto-generated method stub
        if (序号 == -1)
        {
            try {
                M员工信息表.getInstance().setFromObject(
                        FileUtils.File2erializable(FileConstants.SERIALIZABLE_员工信息表));
            } catch (StreamCorruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            序号 = M员工信息表.getInstance().get序号();
        }
        String url = String.format(UrlConstants.UPDATELOCATION, 序号 + "", lat, lng,
                TimeUtils.getNowTime());
        try {
            HttpUtils.getUrlContent(mContext, url, "UTF-8");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public boolean gettrail(Context mContext, String date) {
        // TODO Auto-generated method stub
        if (序号 == -1)
        {
            try {
                M员工信息表.getInstance().setFromObject(
                        FileUtils.File2erializable(FileConstants.SERIALIZABLE_员工信息表));
            } catch (StreamCorruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            序号 = M员工信息表.getInstance().get序号();
        }
        String url = String.format(UrlConstants.GETTRAIL, 序号 + "", date);
        String str = "";
        try {
            str = HttpUtils.getUrlContent(mContext, url, "UTF-8");
            List mList = JsonUtils.getList(str);
            FileUtils.Serializable2File((Serializable) mList, FileConstants.SERIALIZABLE_员工轨迹);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
